package com.example.a14110100409.yuejiandemo.fragment;

import android.content.Context;
import android.content.Intent;
import android.support.v4.app.Fragment;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.a14110100409.yuejiandemo.R;
import com.example.a14110100409.yuejiandemo.adapter.ClubInfoAdapter;
import com.example.a14110100409.yuejiandemo.adapter.ClubListAdapter;
import com.example.a14110100409.yuejiandemo.javabean.Club;
import com.example.a14110100409.yuejiandemo.model.ClubModel;

import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class ClubInfoFragment extends Fragment {
    private RecyclerView recyclerView;
    private Context mContext;
    private String club_id;
    private Club clubinfo;
    private ImageView coachPhoto;
    private TextView coachName,clubinfoContent,tellContent,coachinfo;
    private List<Club.ClubteacherEntity> Data;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        View view = inflater.inflate(R.layout.activity_club_info_fragment,container,false);
        coachName = (TextView) view.findViewById(R.id.coachName);
        clubinfoContent = (TextView) view.findViewById(R.id.clubinfoContent);
        tellContent = (TextView) view.findViewById(R.id.tellContent);
        coachinfo = (TextView) view.findViewById(R.id.coachinfo);
        coachPhoto = (ImageView) view.findViewById(R.id.coachPhoto);
        Intent intent = getActivity().getIntent();
        club_id = intent.getStringExtra("club_id");
        recyclerView = (RecyclerView) view.findViewById(R.id.clubinfo_rv);
        recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));//设置布局
        showData();
        return view;
    }

    private void showData(){
        ClubModel clubModel = new ClubModel();
        Call<Club> call = clubModel.getclubinfo(club_id);
        call.enqueue(new Callback<Club>() {
            @Override
            public void onResponse(Call<Club> call, Response<Club> response) {
                clubinfo = response.body();
                clubinfoContent.setText(clubinfo.getIntroduction());
                tellContent.setText(clubinfo.getClub_tel());
                Data=response.body().getClubteacher();
                recyclerView.setAdapter(new ClubInfoAdapter(getActivity(),Data));
            }
            @Override
            public void onFailure(Call<Club> call, Throwable t) {

            }
        });
    }
}
